﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wicresoft.RDW.Presentation;
using Resources;
using System.Linq.Expressions;

namespace Wicresoft.RDW.Report
{
    public partial class SysLog : BasePage_BackEnd
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            PagerControll.PageChange += new Wicresoft.RDW.UserControls.PagerControl.PageRefresh(PagerControll_PageChange);
            if (!this.IsPostBack)
            {
                InitControlResource();
                PagerControll_PageChange(0);
            }

        }

        protected void GvSysLog_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                int i = 0;
                e.Row.Cells[i++].Text = (e.Row.RowIndex + 1 + (PagerControll.CurrentPageIndex) * PagerControll.PageSize).ToString();
                var user = UserPresent.GetById(int.Parse(e.Row.Cells[++i].Text));
                if (user != null)
                    e.Row.Cells[i].Text = user.Account;
                else
                    e.Row.Cells[i].Text = "找不到User";
            }
        }

        public override void InitControlResource()
        {
            int i = 0;
            GvSysLog.Columns[i++].HeaderText = Resources.NameResource.No;
            GvSysLog.Columns[i++].HeaderText = Resources.NameResource.Syslog_Time;
            GvSysLog.Columns[i++].HeaderText = Resources.NameResource.Syslog_Name;
            GvSysLog.Columns[i++].HeaderText = Resources.NameResource.Syslog_Desc;

            //var sysLog = SysLogPresent.GetList().OrderBy(g => g.CreateTime).ToList();
            //GvSysLog.DataSource = sysLog;
            //GvSysLog.DataBind();
        }

        void PagerControll_PageChange(int pageIndex)
        {
            var sysLog = SysLogPresent.GetPaged(pageIndex, PagerControll.PageSize, g => g.CreateTime,true);
            GvSysLog.DataSource = sysLog;
            GvSysLog.DataBind();
            PagerControll.IntialProperties(sysLog.TotalCount);
        }
    }
}